/*************************************************************************
> File Name: score.cpp
> Author: hzy
> Created Time: 2023-08-18 15:03:51
> Description:求5名选手的平均值
************************************************************************/
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdlib>

using namespace std;

class Person
{
private:
    double score;

public:
    void set_score(double score)
    {
        this->score = score;
    }
    double get_score() const
    {
        return score;
    }
};

double get_avg_score()
{
    vector<double> score_vector;
    for (int i = 0; i < 10; i++)
    {
        score_vector.push_back(rand() % 10);
    }
    // sort算法，对平均值进行排序
    sort(score_vector.begin(), score_vector.end());
    //将成绩存储到deque容器中
    deque<double> score_deque(score_vector.begin(), score_vector.end());
    //删除最高分
    score_deque.pop_back();
    //删除最低分
    score_deque.pop_front();
    double sum = 0;
    for (int i = 0; i < 8; i++)
    {
        sum += score_deque.back();
        score_deque.pop_back();
    }
    return sum / 8;
}

int main(int argc, char const *argv[])
{
    srand((unsigned)time(NULL));
    vector<Person> group;
    for (int i = 0; i < 5; i++)
    {
        group.push_back(Person());
    }
    for (int i = 0; i < 5; i++)
    {
        Person &temp = group.at(i);
        temp.set_score(get_avg_score());
    }
    for (int i = 0; i < 5; i++)
    {
        cout << group.at(i).get_score() << endl;
    }

    return 0;
}